with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

with Parser;

procedure Test_Parser is

   procedure Print_Chars (Str : in Unbounded_String) is
      Ch : Character;
   begin
      for J in 1 .. Length (Str) loop
	 Ch := Element (Str, J);
	 if Ch = LF then
	    Put ("'LF' ");
	 elsif Ch = CR then
	    Put ("'CR' ");
	 else
	    Put ("'" & Ch & "' ");
	 end if;
      end loop;
   end Print_Chars;

   Test_Str_1 : String := ('H', 'e', 'l', 'l', 'o', LF, LF);
   Test_Str_2 : String := ('H', 'e', 'l', 'l', 'o', CR, LF, CR, LF);
   Test_Str_3 : String := ('H', 'e', 'l', 'l', 'o', CR, CR);
   
   Unified_Str_1 : Unbounded_String := Parser.Unify_Line_Ends (
     To_Unbounded_String (Test_Str_1));
   Unified_Str_2 : Unbounded_String := Parser.Unify_Line_Ends (
     To_Unbounded_String (Test_Str_2));
   Unified_Str_3 : Unbounded_String := Parser.Unify_Line_Ends (
     To_Unbounded_String (Test_Str_3));
     
begin
   if Length (Unified_Str_1) = Length (Unified_Str_2) and then
     Length (Unified_Str_2) = Length (Unified_Str_3) then
      for J in 1 .. Length (Unified_Str_1) loop
	 if Element (Unified_Str_1, J) /= Element (Unified_Str_2, J) or else
	   Element (Unified_Str_2, J) /= Element (Unified_Str_3, J) or else
	   Element (Unified_Str_1, J) /= Element (Unified_Str_3, J) then
	    Put_Line ("Test failed, elements " & Natural'Image (J) &
	      " are not equal.");
	 end if;
      end loop;
   else
      Put_Line ("Test failed, length of strings are not equal.");
      
      Put ("  Length of Unified_Str_1: " &
        Natural'Image (Length (Unified_Str_1)) & ": ");
      Print_Chars (Unified_Str_1);
      New_Line;
      
      Put_Line ("  Length of Unified_Str_2: " &
        Natural'Image (Length (Unified_Str_2)));
      Print_Chars (Unified_Str_2);
      New_Line;
	
      Put_Line ("  Length of Unified_Str_3: " &
        Natural'Image (Length (Unified_Str_3)));
      Print_Chars (Unified_Str_3);
      New_Line;
   end if;
   
   Put_Line ("Test finished");
end Test_Parser;
